package com.usian.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.article.service.AuthorService;
import com.usian.article.AuthorControllerApi;
import com.usian.model.article.pojo.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/article/api/v1")
@RestController
public class AuthorController implements AuthorControllerApi {

    @Autowired
    private AuthorService authorService;
    /*
    * 根据UserId查询作者的信息
    * */
    @GetMapping("findById/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable("id") Integer id) {
        return authorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId,id));
    }
    /*
    * 保存作者的信息
    * */
    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        authorService.save(apAuthor);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
